home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / dev / src / wangisrc.lha / wangi / z / oldwp / Prefs / Window_Main.PAS < prev    next >
Pascal/Delphi Source File  |  1995-02-25  |  12KB  |  373 lines

  1. { add window to wb app. list }
  2. Function AddAppWin(VAR aw : pAppWindow; VAR w : pWindow; VAR Port : pMsgPort) : Boolean;
  3.  
  4. Begin
  5.     AddAppWin := False;
  6.     Port := CreateMsgPort;
  7.     if Port <> NIL then begin
  8.         aw := AddAppWindowA(0,0,w,Port,NIL);
  9.         { don't check, it fails if wb not running }
  10.         AddAppWin := True;
  11.     End; 
  12. End;
  13.  
  14. Procedure RemoveAppWin(VAR aw : pAppWindow; VAR Port : pMsgPort);
  15.  
  16. Var
  17.     Ok : Boolean;
  18.     m  : pMessage;
  19.     
  20. Begin
  21.     if (Port <> NIL) then begin
  22.         m := GetMsg(Port);
  23.         While m <> NIL do begin
  24.             ReplyMsg(m);
  25.             m := GetMsg(Port);
  26.         End;
  27.     End;
  28.     if aw <> NIL then begin
  29.         Ok := RemoveAppWindow(aw);
  30.         aw := NIL;
  31.     End;
  32.     if Port <> NIL then begin
  33.         DeleteMsgPort(Port);
  34.         Port := NIL;
  35.     End;
  36. End;
  37.  
  38.  
  39.  
  40. Procedure DisableGadget;
  41.  
  42. VAR Dis_Tags : array[0..1] of tTagItem;
  43.  
  44. begin
  45.     Dis_Tags[0].ti_Tag  := GA_Disabled;
  46.     Dis_Tags[0].ti_Data := Disable;
  47.     Dis_Tags[1].ti_Tag  := TAG_END;
  48.     GT_SetGadgetAttrsA(g,w,NIL,@Dis_Tags);
  49. end;
  50.  
  51. (*
  52.  * A little routine to fill in the members of a NewMenu struct
  53.  *
  54.  * Cheat & use a bit of assembler to get direct access to the embedded
  55.  * string constants
  56.  *)
  57. procedure nm(var mnm: tNewMenu;
  58.     nmType: byte;
  59.     nmLabel: string;
  60.     nmCommKey: string;
  61.     nmFlags: word;
  62.     nmMutualExclude: longint;
  63.     nmUserData: LONG); assembler;
  64. asm
  65.     move.l    mnm,a0                        { address of the element }
  66.     move.b    nmType,tNewMenu.nm_Type(a0)    { copy the type }
  67.  
  68.     move.l    nmLabel,a1                    { the address of the Pascal string }
  69.     tst.b    (a1)+                        { check for zero length & skip length byte }
  70.     bne        @1                            { if not zero, nothing to do }
  71.     move.l    #NM_BARLABEL,a1                { substitute empty strings with a bar }
  72. @1:    move.l    a1,tNewMenu.nm_Label(a0)    { store the C string }
  73.  
  74.     move.l    nmCommKey,a1                { same for the CommKey }
  75.     tst.b    (a1)+
  76.     bne        @2
  77.     suba.l    a1,a1                        { use nil if the empty string }
  78. @2:    move.l    a1,tNewMenu.nm_CommKey(a0)
  79.  
  80. { the remaining fields }
  81.     move.w    nmFlags,tNewMenu.nm_Flags(a0)
  82.     move.l    nmMutualExclude,tNewMenu.nm_MutualExclude(a0)
  83.     move.l    nmUserData,tNewMenu.nm_UserData(a0)
  84. end;
  85.  
  86.  
  87. { open the main window }
  88. Function open_window;
  89.  
  90. Var 
  91.     tgs       : Array[0..16] Of tTagItem;
  92.     sampTxt   : tIntuiText;
  93.     screendef : pScreen;
  94.     OK        : Boolean;
  95.     nd        : pNode;
  96.     n         : Integer;
  97.   mm        : Array[0..13] of tNewMenu;
  98.  
  99. Begin
  100.     Open_Window := False;
  101.     nm(mm[ 0], NM_TITLE, 'Project'#0, '', 0, 0, 0);
  102.     nm(mm[ 1], NM_ITEM , 'Open...'#0, 'O'#0, 0, 0, MI_OPEN);
  103.     nm(mm[ 2], NM_ITEM , 'Append...'#0, 'N'#0, 0, 0, MI_APPE);
  104.     nm(mm[ 3], NM_ITEM , 'Save As...'#0, 'A'#0, 0, 0, MI_SAVA);
  105.     nm(mm[ 4], NM_ITEM , '', '', 0, 0, 0);
  106.     nm(mm[ 5], NM_ITEM , 'About'#0, '?'#0, 0, 0, MI_INFO);
  107.     nm(mm[ 6], NM_ITEM , '', '', 0, 0, 0);
  108.     nm(mm[ 7], NM_ITEM , 'Quit'#0, 'Q'#0, 0, 0, MI_QUIT);
  109.     
  110.     nm(mm[ 8], NM_TITLE, 'Edit'#0, '', 0, 0, 0);
  111.     nm(mm[ 9], NM_ITEM , 'Reset To Defaults'#0, 'D'#0, 0, 0, MI_RDEF);
  112.     nm(mm[10], NM_ITEM , 'Restore'#0, 'R'#0, 0, 0, MI_REST);
  113.     
  114.     nm(mm[11], NM_TITLE, 'Settings'#0, '', 0, 0, 0);
  115.     nm(mm[12], NM_ITEM , 'Create Icons?'#0, 'I'#0, NM_ITEMDISABLED|CHECKIT|MENUTOGGLED, 0, 0);
  116.     nm(mm[13], NM_END  , '', '', 0, 0, 0);
  117.     
  118.     WindowIDCMP := INTEGERIDCMP Or IDCMP_REFRESHWINDOW 
  119.         Or BUTTONIDCMP Or LISTVIEWIDCMP
  120.         OR CHECKBOXIDCMP OR IDCMP_VANILLAKEY OR IDCMP_MENUPICK or IDCMP_CLOSEWINDOW;
  121.     gads[G_NI]  := NIL;
  122.    
  123.     ScreenDef := LockPubScreen(NIL);
  124.  
  125.     { Get visual info and create context }
  126.     vi := GetVisualInfoA(screendef, NIL);
  127.     If vi <> NIL Then begin
  128.         Gads[G_CC] := CreateContext(@gads[G_NI]);
  129.         If Gads[G_CC] <> NIL Then begin
  130.             { Get some data from the screen }
  131.  
  132.             Sizes[TBS]   := screendef^.WBorTop + (screendef^.Font^.ta_YSize + 1);
  133.  
  134.             My_Font := Screendef^.Font^;
  135.             if (My_Font.ta_YSize*(ListViewRows+5)>Screendef^.Height) then begin 
  136.                 with My_Font do begin
  137.                     ta_Name    := CStrConstPtrAR(@RememberKey, 'topaz.font');
  138.                     ta_YSize   := 8;
  139.                     ta_Style   := FS_NORMAL;
  140.                     ta_Flags   := FPF_ROMFONT
  141.                 end;
  142.                 Sizes[S_Gad_H] := 9+screendef^.WBorTop+1;
  143.             end else
  144.                 Sizes[S_Gad_H] := sizes[TBS] + 1;
  145.                 
  146.             Sizes[S_CM_W] := (Sizes[S_Gad_H]*2)+(Sizes[S_Gad_H] div 3);
  147.  
  148.             ZoomSizes[3] := Sizes[TBS];
  149.    
  150.             sizes[S_WB_T]    := Screendef^.WBorTop;
  151.             sizes[S_WB_L]    := Screendef^.WBorLeft;
  152.             sizes[S_WB_R]    := Screendef^.WBorRight;
  153.             sizes[S_WB_B]    := Screendef^.WBorBottom;
  154.    
  155.             Samptxt.ITextFont := @My_Font;
  156.             Sizes[S_G1_L] := Sizes[S_WB_L] + Sizes[S_WB_L];
  157.             Samptxt.IText := @G_B_BOTTOMtxt[1];
  158.             Sizes[S_G1_W] := IntuiTextLength(@Samptxt) + 10;
  159.             Samptxt.IText := @Sampstr[1];
  160.             Sizes[S_G2_W] := IntuiTextLength(@Samptxt) + 10;
  161.             Sizes[S_G2_L] := sizes[S_G1_L] + sizes[S_G1_W] + sizes[S_WB_L];
  162.             Samptxt.IText := @sampstr2[1];
  163.             Sizes[S_G3_W] := IntuiTextLength(@Samptxt) + 20;
  164.             Sizes[S_G3_L] := sizes[S_G2_L] + sizes[S_G2_W] + 6;
  165.             Samptxt.IText := CStrConstPtrAR(@RememberKey, 'System options...');
  166.             sizes[extra] := IntuiTextLength(@Samptxt);
  167.             Samptxt.IText := CStrConstPtrAR(@RememberKey, 'The Requesters');
  168.             sizes[S_SCRID_W] := IntuiTextLength(@Samptxt) + 20;
  169.             Samptxt.IText := CStrConstPtrAR(@RememberKey, 'ARexx Command');
  170.             Sizes[TxtWin_L] := IntuiTextLength(@Samptxt) + 25;
  171.             Samptxt.IText := CStrConstPtrAR(@RememberKey, 'Initial ARexx command');
  172.             Sizes[RexxWin_L] := IntuiTextLength(@Samptxt) + 25;
  173.             Samptxt.IText := CStrConstPtrAR(@RememberKey, 'ASynch ');
  174.             Sizes[Synch_W] := IntuiTextLength(@Samptxt) + 7;
  175.             Samptxt.IText := CStrConstPtrAR(@RememberKey, 'Sanghai windows to default public screen ');
  176.             Sizes[SOTxt_W] := IntuiTextLength(@Samptxt) + 20;
  177.             Samptxt.IText := CStrConstPtrAR(@RememberKey, 'Middle Mouse Button');
  178.             Sizes[QTxt_W] := IntuiTextLength(@Samptxt) + 20; 
  179.             
  180.             { Initilise gadget structures }
  181.             tgs[0].ti_Tag  := GA_Disabled;
  182.             tgs[0].ti_Data := True_;
  183.             tgs[1].ti_Tag  := GT_UnderScore;
  184.             tgs[1].ti_Data := LONG('_');
  185.             tgs[2].ti_Tag  := TAG_END;
  186.    
  187.             With GadgetFlags Do Begin
  188.                 ng_TextAttr   := @My_Font;
  189.                 ng_LeftEdge   := sizes[S_G1_L]+5+BF_W;
  190.                 ng_TopEdge    := (Sizes[TBS]+Sizes[S_Gad_H])+(Sizes[S_Gad_H] div 2)+BF_H;
  191.                 ng_Width      := Sizes[S_G1_W];
  192.                 ng_Height     := Sizes[S_GAD_H];
  193.                 ng_GadgetText := @G_B_TOPtxt[1];
  194.                 ng_VisualInfo := vi;
  195.                 ng_GadgetID   := G_B_TOP;
  196.             End;
  197.             { create gadgets }
  198.             Gads[G_B_TOP] := CreateGadgetA(BUTTON_KIND, Gads[G_CC], @Gadgetflags, @tgs);
  199.                
  200.             With GadgetFlags Do Begin
  201.                 ng_TopEdge    := ng_TopEdge + Sizes[S_Gad_H];
  202.                 ng_GadgetText := @G_B_UPtxt[1];
  203.                 ng_GadgetID   := G_B_UP;
  204.             End;
  205.             Gads[G_B_UP] := CreateGadgetA(BUTTON_KIND, Gads[G_B_TOP], @Gadgetflags, @tgs);
  206.                
  207.             With GadgetFlags Do Begin
  208.                 ng_TopEdge    := ng_TopEdge + Sizes[S_Gad_H];
  209.                 ng_GadgetText := @G_B_DOWNtxt[1];
  210.                 ng_GadgetID   := G_B_DOWN;
  211.             End;
  212.             Gads[G_B_DOWN] := CreateGadgetA(BUTTON_KIND, Gads[G_B_UP], @Gadgetflags, @tgs);
  213.                
  214.             With GadgetFlags Do Begin
  215.                 ng_TopEdge    := ng_TopEdge + Sizes[S_Gad_H];
  216.                 ng_GadgetText := @G_B_BOTTOMtxt[1];
  217.                 ng_GadgetID   := G_B_BOTTOM;
  218.             End;
  219.             Gads[G_B_BOTTOM] := CreateGadgetA(BUTTON_KIND, Gads[G_B_DOWN], @Gadgetflags, @tgs);
  220.             
  221.             tgs[0].ti_Data := False_;
  222.             With GadgetFlags Do Begin
  223.                 ng_TopEdge    := ng_TopEdge + Sizes[S_Gad_H];
  224.                 ng_GadgetText := @G_B_SORTtxt[1];
  225.                 ng_GadgetID   := G_B_SORT;
  226.             End;
  227.             Gads[G_B_SORT] := CreateGadgetA(BUTTON_KIND, Gads[G_B_BOTTOM], @Gadgetflags, @tgs);
  228.             
  229.             With GadgetFlags Do Begin
  230.                 ng_TopEdge    := ng_TopEdge + Sizes[S_Gad_H];
  231.                 ng_GadgetText := @G_B_NEWtxt[1];
  232.                 ng_GadgetID   := G_B_NEW;
  233.             End;
  234.             Gads[G_B_NEW] := CreateGadgetA(BUTTON_KIND, Gads[G_B_SORT], @Gadgetflags, @tgs);
  235.  
  236.             tgs[0].ti_Data := True_;
  237.             With GadgetFlags Do Begin
  238.                 ng_TopEdge    := ng_TopEdge + Sizes[S_Gad_H];
  239.                 ng_GadgetText := @G_B_REMOVEtxt[1];
  240.                 ng_GadgetID   := G_B_REMOVE;
  241.             End;
  242.             Gads[G_B_REMOVE] := CreateGadgetA(BUTTON_KIND, Gads[G_B_NEW], @Gadgetflags, @tgs);
  243.             
  244.             With GadgetFlags Do Begin
  245.                 ng_TopEdge    := ng_TopEdge + Sizes[S_Gad_H];
  246.                 ng_GadgetText := @G_B_COPYtxt[1];
  247.                 ng_GadgetID   := G_B_COPY;
  248.             End;
  249.             Gads[G_B_COPY] := CreateGadgetA(BUTTON_KIND, Gads[G_B_REMOVE], @Gadgetflags, @tgs);
  250.                
  251.             tgs[0].ti_Data := False_;
  252.             tgs[2].ti_Tag  := GTLV_ShowSelected;
  253.             tgs[2].ti_Data := 0;
  254.             tgs[3].ti_Tag  := GTLV_Labels;
  255.             tgs[3].ti_Data := LONG(CurrentList);
  256.             tgs[4].ti_Tag  := TAG_END;
  257.             With GadgetFlags Do Begin
  258.                 ng_Height     := (ng_TopEdge+ng_Height)-((Sizes[TBS]+Sizes[S_Gad_H])+(Sizes[S_Gad_H] div 2));
  259.                 ng_LeftEdge   := sizes[S_G2_L]+5+BF_W;
  260.                 ng_TopEdge    := (Sizes[TBS]+Sizes[S_Gad_H])+(Sizes[S_Gad_H] div 2)+BF_H;
  261.                 ng_Width      := Sizes[S_G2_W];
  262.                 ng_GadgetText := CStrConstPtrAR(@RememberKey, 'List Items');
  263.                 ng_GadgetID   := G_LV;
  264.                 ng_Flags      := PLACETEXT_ABOVE|NG_HIGHLABEL;
  265.             End;
  266.             Gads[G_LV] := CreateGadgetA(LISTVIEW_KIND, Gads[G_B_COPY], @Gadgetflags, @tgs);
  267.  
  268.             Listviewrows := GadgetFlags.ng_Height div My_Font.ta_YSize;
  269.             
  270.             Labs[0] := CStrConstPtrAR(@RememberKey, 'Font');
  271.             Labs[1] := CStrConstPtrAR(@RememberKey, 'Window Title');
  272.             Labs[2] := CStrConstPtrAR(@RememberKey, 'Screen Title');
  273.             Labs[3] := CStrConstPtrAR(@RememberKey, 'Window');
  274.             
  275.             SetList := AllocRemember(@Rememberkey, Sizeof(tList), MEMF_CLEAR);
  276.             if SetList = NIL then Halt;
  277.             NewList(SetList);
  278.             For n := 0 to LabMax do begin
  279.                 nd := AllocRemember(@RememberKey, Sizeof(tNode), MEMF_CLEAR);
  280.                 if nd <> NIL then begin
  281.                     nd^.ln_Name := Labs[n];
  282.                     AddTail(SetList, nd);
  283.                 End;
  284.             End;
  285.  
  286.             tgs[3].ti_Data := LONG(SetList);
  287.             With GadgetFlags Do Begin
  288.                 ng_LeftEdge   := ng_LeftEdge+ng_Width+8;
  289.                 ng_GadgetText := CStrConstPtrAR(@RememberKey, 'Settings');
  290.                 ng_GadgetID   := G_C_SET;
  291.                 ng_Flags      := PLACETEXT_ABOVE|NG_HIGHLABEL;
  292.                 ng_Width      := Sizes[S_G2_W];
  293.             End;
  294.             Gads[G_C_SET] := CreateGadgetA(LISTVIEW_KIND, Gads[G_LV], @Gadgetflags, @tgs);
  295.  
  296.             tgs[2].ti_Tag  := TAG_DONE;
  297.             With GadgetFlags Do Begin
  298.                 ng_Height     := Sizes[S_GAD_H];
  299.                 ng_TopEdge    := gads[G_B_COPY]^.TopEdge + gads[G_B_COPY]^.Height + 8 + BF_H;
  300.                 If NOT V39 then ng_TopEdge := ng_TopEdge + Sizes[S_Gad_H];
  301.                 ng_LeftEdge   := sizes[S_G1_L]+5;
  302.                 ng_Width      := Sizes[S_G1_W]+25;
  303.                 ng_GadgetText := @G_B_SAVEtxt[1];
  304.                 ng_Flags      := 0;
  305.                 ng_GadgetID   := G_B_SAVE;
  306.             End;
  307.             Gads[G_B_SAVE] := CreateGadgetA(BUTTON_KIND, Gads[G_C_SET], @Gadgetflags, @tgs);
  308.               
  309.             With GadgetFlags Do Begin
  310.                 ng_Leftedge   := Gads[G_C_SET]^.LeftEdge+Gads[G_C_SET]^.Width-ng_Width+BF_W;
  311.                 ng_GadgetText := @G_B_CANCELtxt[1];
  312.                 ng_GadgetID   := G_B_CANCEL;
  313.             End;
  314.             Gads[G_B_CANCEL] := CreateGadgetA(BUTTON_KIND, Gads[G_B_SAVE], @Gadgetflags, @tgs);
  315.                         
  316.             { window structure }
  317.             tgs[0].ti_Tag  := WA_Left;
  318.             tgs[0].ti_Data := 0;
  319.             tgs[1].ti_Tag  := WA_Top;
  320.             tgs[1].ti_Data := Sizes[TBS];
  321.             tgs[2].ti_Tag  := WA_InnerWidth;
  322.             tgs[2].ti_Data := GadgetFlags.ng_LeftEdge+GadgetFlags.ng_Width+8;
  323.             tgs[3].ti_Tag  := WA_Height;
  324.             tgs[3].ti_Data := gads[G_B_SAVE]^.TopEdge + gads[G_B_SAVE]^.Height+6;
  325.             tgs[4].ti_Tag  := WA_Title;
  326.             tgs[4].ti_Data := LONG(@Win_Title[1]); 
  327.             tgs[5].ti_Tag  := WA_IDCMP;
  328.             tgs[5].ti_Data := WindowIDCMP;
  329.             tgs[6].ti_Tag  := WA_CloseGadget;
  330.             tgs[6].ti_Data := True_;
  331.             tgs[7].ti_Tag  := WA_DragBar;
  332.             tgs[7].ti_Data := True_;
  333.             tgs[8].ti_Tag  := WA_DepthGadget;
  334.             tgs[8].ti_Data := True_;
  335.             tgs[9].ti_Tag  := WA_AutoAdjust;
  336.             tgs[9].ti_Data := True_;
  337.             tgs[10].ti_Tag := WA_Activate;
  338.             tgs[10].ti_Data:= True_;
  339.             tgs[11].ti_Tag := WA_Gadgets;
  340.             tgs[11].ti_Data:= LONG(gads[G_NI]);
  341.             tgs[12].ti_Tag := WA_Zoom;
  342.             tgs[12].ti_Data:= LONG(@ZoomSizes);
  343.             tgs[13].ti_Tag := $80000093 {WA_NewLookMenus};
  344.             tgs[13].ti_Data:= True_;
  345.             tgs[14].ti_Tag := WA_ScreenTitle;
  346.             tgs[14].ti_Data:= LONG(@Scr_Title[1]);
  347.             tgs[15].ti_Tag := WA_SimpleRefresh;
  348.             tgs[15].ti_Data:= True_;
  349.             tgs[16].ti_Tag := TAG_DONE;
  350.   
  351.             TheWindow := OpenWindowTaglist(NIL,@tgs);
  352.             If TheWindow <> NIL Then begin 
  353.  
  354.                 tgs[0].ti_Tag  := $80080043 {GTMN_NewLookMenus};
  355.                 tgs[0].ti_Data := True_;
  356.                 tgs[1].ti_Tag  := TAG_END;
  357.                 menustrip := CreateMenusA(@mm, NIL);
  358.                 if menustrip <> NIL then
  359.                     if LayoutMenusA(menustrip,vi,@tgs) then
  360.                         OK := SetMenuStrip(TheWindow,MenuStrip);
  361.                         
  362.                 InitBackFill(bf, TheWindow, Sizes[S_WB_L], Sizes[TBS], Tgs[2].ti_Data, 
  363.              Tgs[3].ti_Data-Sizes[TBS]-Sizes[S_WB_B], BF_W, BF_H, BBF_H, 2, 0, JAM1); 
  364.         
  365.                 GT_RefreshWindow(TheWindow, NIL);
  366.                 RefreshGList(gads[G_NI], TheWindow, NIL, -1);
  367.                 
  368.                 Open_Window := True;
  369.             end;
  370.         end;
  371.     end; 
  372.     UnlockPubScreen(NIL, ScreenDef); 
  373. End;